package com.wanshi.servlet;

import com.wanshi.entity.PageInfo;
import com.wanshi.request.ProdReq;
import com.wanshi.service.ProdService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/findProdByPage")
public class findProdByPage extends HttpServlet {

    private ProdService prodService = new ProdService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 获取数据   带条件的分页   page  size  条件 name  typeid
        ProdReq prodReq = new ProdReq();
        try {
            BeanUtils.copyProperties(prodReq,request.getParameterMap());

            PageInfo info = prodService.findByPageAndCond(prodReq);

            request.setAttribute("page",info);
            request.getRequestDispatcher("/page.jsp").forward(request,response);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

